package com.goodmr.passport.webapp.Serivce.impl;

import com.goodmr.passport.account.AccountModel;
import com.goodmr.passport.password.PasswordDao;
import com.goodmr.passport.webapp.Serivce.PasswordService;
import com.goodmr.passport.webapp.model.request.ChangePasswordReq;
import com.goodmr.passport.webapp.model.request.SetPasswordReq;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;

/**
 * 帐号密码设置服务
 *
 * @author <a href="mailto:bingdong13@msn.com">bigo</a>
 */
@Service("setPasswordService")
public class SetPasswordServiceImpl extends AccountServiceImpl implements PasswordService {

    @Autowired
    private PasswordDao passwordDao;

    /**
     * 帐号密码设置
     *
     * @param data 帐号密码信息
     */
    @Override
    public void modify(@NonNull ChangePasswordReq data) {

        SetPasswordReq body = (SetPasswordReq) data;

        validatePassword(body.getPassword());

        AccountModel model = accountDao.findById(body.getAccountId());

        validateCode(model.getAccount(), body.getCode());

        // 修改密码
        passwordDao.modify(body.getAccountId(), body.getPassword());
    }
}
